package class01;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class LocalDateTest {
    public static void main(String[] args) {
        // 获取当前日期
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
        //        getDayOfMonth()/getDayOfYear()	获得月份天数(1-31) /获得年份天数(1-366)
        System.out.println(localDate.getDayOfMonth());
//getDayOfWeek()	获得星期几(返回一个 DayOfWeek 枚举值)
        System.out.println(localDate.getDayOfWeek());
//getMonth()	获得月份, 返回一个 Month 枚举值
        System.out.println(localDate.getMonth());
//getMonthValue() / getYear()	获得月份(1-12) /获得年份
        System.out.println(localDate.getMonthValue());
        // 获取当前时间
        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);
        // 获取当前日期和时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        //
        // 方式一：预定义的标准格式。如：ISO_LOCAL_DATE_TIME;ISO_LOCAL_DATE;ISO_LOCAL_TIME
        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        // 格式化:日期-->字符串
        LocalDateTime localDateTime = LocalDateTime.now();
        String str1 = formatter.format(localDateTime);
        System.out.println(localDateTime);
        System.out.println(str1);//2022-12-04T21:02:14.808

        // 解析：字符串 -->日期
        TemporalAccessor parse = formatter.parse("2022-12-04T21:02:14.808");
        LocalDateTime dateTime = LocalDateTime.from(parse);
        System.out.println(dateTime);






    }
}
